#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
// using std::placeholders::_1;
using namespace std::placeholders;

bool isShorter(const string &s1, const string &s2)
{
    return s1.size() < s2.size();
}
bool check_size(const string &s, string::size_type sz)
{
    return s.size() >= sz;
}

int main()
{
    /* code */
    vector<string> words;
    words.push_back("hello");
    words.push_back("you");
    words.push_back("we");
    words.push_back("i");
    vector<string>::size_type sz = 3;
    //bind只拷贝参数，引用必须用ref()/cref()
    auto nc = bind(check_size, _1, cref(sz));
    sz = 2;
    auto s = [=](const string &s1, const string &s2){return s1.size() < s2.size();};
    sort(words.begin(), words.end(), s);

    auto f = [&sz](const string &s1){ return s1.size() >= sz; };    //尽量避免捕获指针和引用
    sz = 3;
    for (const auto &word : words)
    {
        cout << word << endl;
    }

    auto wc = find_if(words.begin(), words.end(), nc);
    for_each(wc, words.end(), [](const string &s1)
             { cout << s1 << ' '; });
    cout << endl;

    

    return 0;
}
